
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_Hans">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Django 3.1 release notes &#8212; Django 3.2.6.dev 文档</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="next" title="Django 3.0.14 release notes" href="3.0.14.html" />
    <link rel="prev" title="Django 3.1.1 release notes" href="3.1.1.html" />



 
<script src="../templatebuiltins.js"></script>
<script>
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../ref/templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);</script>

  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../index.html">Django 3.2.6.dev 文档</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../index.html">Home</a>  |
        <a title="Table of contents" href="../contents.html">Table of contents</a>  |
        <a title="Global index" href="../genindex.html">Index</a>  |
        <a title="Module index" href="../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="3.1.1.html" title="Django 3.1.1 release notes">previous</a>
     |
    <a href="index.html" title="Release notes" accesskey="U">up</a>
   |
    <a href="3.0.14.html" title="Django 3.0.14 release notes">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="releases-3.1">
            
  <div class="section" id="s-django-3-1-release-notes">
<span id="django-3-1-release-notes"></span><h1>Django 3.1 release notes<a class="headerlink" href="#django-3-1-release-notes" title="永久链接至标题">¶</a></h1>
<p><em>August 4, 2020</em></p>
<p>Welcome to Django 3.1!</p>
<p>These release notes cover the <a class="reference internal" href="#whats-new-3-1"><span class="std std-ref">new features</span></a>, as well as
some <a class="reference internal" href="#backwards-incompatible-3-1"><span class="std std-ref">backwards incompatible changes</span></a> you'll
want to be aware of when upgrading from Django 3.0 or earlier. We've
<a class="reference internal" href="#removed-features-3-1"><span class="std std-ref">dropped some features</span></a> that have reached the end of
their deprecation cycle, and we've <a class="reference internal" href="#deprecated-features-3-1"><span class="std std-ref">begun the deprecation process for
some features</span></a>.</p>
<p>See the <a class="reference internal" href="../howto/upgrade-version.html"><span class="doc">升级 Django 到最新的版本</span></a> guide if you're updating an existing
project.</p>
<div class="section" id="s-python-compatibility">
<span id="python-compatibility"></span><h2>Python compatibility<a class="headerlink" href="#python-compatibility" title="永久链接至标题">¶</a></h2>
<p>Django 3.1 supports Python 3.6, 3.7, 3.8, and 3.9 (as of 3.1.3). We <strong>highly
recommend</strong> and only officially support the latest release of each series.</p>
</div>
<div class="section" id="s-what-s-new-in-django-3-1">
<span id="s-whats-new-3-1"></span><span id="what-s-new-in-django-3-1"></span><span id="whats-new-3-1"></span><h2>What's new in Django 3.1<a class="headerlink" href="#what-s-new-in-django-3-1" title="永久链接至标题">¶</a></h2>
<div class="section" id="s-asynchronous-views-and-middleware-support">
<span id="asynchronous-views-and-middleware-support"></span><h3>Asynchronous views and middleware support<a class="headerlink" href="#asynchronous-views-and-middleware-support" title="永久链接至标题">¶</a></h3>
<p>Django now supports a fully asynchronous request path, including:</p>
<ul class="simple">
<li><a class="reference internal" href="../topics/http/views.html#async-views"><span class="std std-ref">Asynchronous views</span></a></li>
<li><a class="reference internal" href="../topics/http/middleware.html#async-middleware"><span class="std std-ref">Asynchronous middleware</span></a></li>
<li><a class="reference internal" href="../topics/testing/tools.html#async-tests"><span class="std std-ref">Asynchronous tests and test client</span></a></li>
</ul>
<p>To get started with async views, you need to declare a view using
<code class="docutils literal notranslate"><span class="pre">async</span> <span class="pre">def</span></code>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">async</span> <span class="k">def</span> <span class="nf">my_view</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.5</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">HttpResponse</span><span class="p">(</span><span class="s1">&#39;Hello, async world!&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>All asynchronous features are supported whether you are running under WSGI or
ASGI mode. However, there will be performance penalties using async code in
WSGI mode. You can read more about the specifics in <a class="reference internal" href="../topics/async.html"><span class="doc">Asynchronous support</span></a>
documentation.</p>
<p>You are free to mix async and sync views, middleware, and tests as much as you
want. Django will ensure that you always end up with the right execution
context. We expect most projects will keep the majority of their views
synchronous, and only have a select few running in async mode - but it is
entirely your choice.</p>
<p>Django's ORM, cache layer, and other pieces of code that do long-running
network calls do not yet support async access. We expect to add support for
them in upcoming releases. Async views are ideal, however, if you are doing a
lot of API or HTTP calls inside your view, you can now natively do all those
HTTP calls in parallel to considerably speed up your view's execution.</p>
<p>Asynchronous support should be entirely backwards-compatible and we have tried
to ensure that it has no speed regressions for your existing, synchronous code.
It should have no noticeable effect on any existing Django projects.</p>
</div>
<div class="section" id="s-jsonfield-for-all-supported-database-backends">
<span id="jsonfield-for-all-supported-database-backends"></span><h3>JSONField for all supported database backends<a class="headerlink" href="#jsonfield-for-all-supported-database-backends" title="永久链接至标题">¶</a></h3>
<p>Django now includes <a class="reference internal" href="../ref/models/fields.html#django.db.models.JSONField" title="django.db.models.JSONField"><code class="xref py py-class docutils literal notranslate"><span class="pre">models.JSONField</span></code></a> and
<a class="reference internal" href="../ref/forms/fields.html#django.forms.JSONField" title="django.forms.JSONField"><code class="xref py py-class docutils literal notranslate"><span class="pre">forms.JSONField</span></code></a> that can be used on all
supported database backends. Both fields support the use of custom JSON
encoders and decoders. The model field supports the introspection,
<a class="reference internal" href="../topics/db/queries.html#querying-jsonfield"><span class="std std-ref">lookups, and transforms</span></a> that were previously
PostgreSQL-only:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>

<span class="k">class</span> <span class="nc">ContactInfo</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">data</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">JSONField</span><span class="p">()</span>

<span class="n">ContactInfo</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="p">{</span>
    <span class="s1">&#39;name&#39;</span><span class="p">:</span> <span class="s1">&#39;John&#39;</span><span class="p">,</span>
    <span class="s1">&#39;cities&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s1">&#39;London&#39;</span><span class="p">,</span> <span class="s1">&#39;Cambridge&#39;</span><span class="p">],</span>
    <span class="s1">&#39;pets&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s1">&#39;dogs&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s1">&#39;Rufus&#39;</span><span class="p">,</span> <span class="s1">&#39;Meg&#39;</span><span class="p">]},</span>
<span class="p">})</span>
<span class="n">ContactInfo</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span>
    <span class="n">data__name</span><span class="o">=</span><span class="s1">&#39;John&#39;</span><span class="p">,</span>
    <span class="n">data__pets__has_key</span><span class="o">=</span><span class="s1">&#39;dogs&#39;</span><span class="p">,</span>
    <span class="n">data__cities__contains</span><span class="o">=</span><span class="s1">&#39;London&#39;</span><span class="p">,</span>
<span class="p">)</span><span class="o">.</span><span class="n">delete</span><span class="p">()</span>
</pre></div>
</div>
<p>If your project uses <code class="docutils literal notranslate"><span class="pre">django.contrib.postgres.fields.JSONField</span></code>, plus the
related form field and transforms, you should adjust to use the new fields,
and generate and apply a database migration. For now, the old fields and
transforms are left as a reference to the new ones and are <a class="reference internal" href="#deprecated-jsonfield"><span class="std std-ref">deprecated as
of this release</span></a>.</p>
</div>
<div class="section" id="s-default-hashing-algorithm-settings">
<span id="s-default-hashing-algorithm-usage"></span><span id="default-hashing-algorithm-settings"></span><span id="default-hashing-algorithm-usage"></span><h3><code class="docutils literal notranslate"><span class="pre">DEFAULT_HASHING_ALGORITHM</span></code> settings<a class="headerlink" href="#default-hashing-algorithm-settings" title="永久链接至标题">¶</a></h3>
<p>The new <a class="reference internal" href="../ref/settings.html#std:setting-DEFAULT_HASHING_ALGORITHM"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_HASHING_ALGORITHM</span></code></a> transitional setting allows
specifying the default hashing algorithm to use for encoding cookies, password
reset tokens in the admin site, user sessions, and signatures created by
<a class="reference internal" href="../topics/signing.html#django.core.signing.Signer" title="django.core.signing.Signer"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.core.signing.Signer</span></code></a> and <a class="reference internal" href="../topics/signing.html#django.core.signing.dumps" title="django.core.signing.dumps"><code class="xref py py-meth docutils literal notranslate"><span class="pre">django.core.signing.dumps()</span></code></a>.</p>
<p>Support for SHA-256 was added in Django 3.1. If you are upgrading multiple
instances of the same project to Django 3.1, you should set
<a class="reference internal" href="../ref/settings.html#std:setting-DEFAULT_HASHING_ALGORITHM"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_HASHING_ALGORITHM</span></code></a> to <code class="docutils literal notranslate"><span class="pre">'sha1'</span></code> during the transition, in
order to allow compatibility with the older versions of Django. Note that this
requires Django 3.1.1+. Once the transition to 3.1 is complete you can stop
overriding <a class="reference internal" href="../ref/settings.html#std:setting-DEFAULT_HASHING_ALGORITHM"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_HASHING_ALGORITHM</span></code></a>.</p>
<p>This setting is deprecated as of this release, because support for tokens,
cookies, sessions, and signatures that use SHA-1 algorithm will be removed in
Django 4.0.</p>
</div>
<div class="section" id="s-minor-features">
<span id="minor-features"></span><h3>Minor features<a class="headerlink" href="#minor-features" title="永久链接至标题">¶</a></h3>
<div class="section" id="s-django-contrib-admin">
<span id="django-contrib-admin"></span><h4><a class="reference internal" href="../ref/contrib/admin/index.html#module-django.contrib.admin" title="django.contrib.admin: Django's admin site."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.admin</span></code></a><a class="headerlink" href="#django-contrib-admin" title="永久链接至标题">¶</a></h4>
<ul>
<li><p class="first">The new <code class="docutils literal notranslate"><span class="pre">django.contrib.admin.EmptyFieldListFilter</span></code> for
<a class="reference internal" href="../ref/contrib/admin/index.html#django.contrib.admin.ModelAdmin.list_filter" title="django.contrib.admin.ModelAdmin.list_filter"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ModelAdmin.list_filter</span></code></a> allows filtering on empty values (empty
strings and nulls) in the admin changelist view.</p>
</li>
<li><p class="first">Filters in the right sidebar of the admin changelist view now contain a link
to clear all filters.</p>
</li>
<li><p class="first">The admin now has a sidebar on larger screens for easier navigation. It is
enabled by default but can be disabled by using a custom <code class="docutils literal notranslate"><span class="pre">AdminSite</span></code> and
setting <a class="reference internal" href="../ref/contrib/admin/index.html#django.contrib.admin.AdminSite.enable_nav_sidebar" title="django.contrib.admin.AdminSite.enable_nav_sidebar"><code class="xref py py-attr docutils literal notranslate"><span class="pre">AdminSite.enable_nav_sidebar</span></code></a> to <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
<p>Rendering the sidebar requires access to the current request in order to set
CSS and ARIA role affordances. This requires using
<code class="docutils literal notranslate"><span class="pre">'django.template.context_processors.request'</span></code> in the
<code class="docutils literal notranslate"><span class="pre">'context_processors'</span></code> option of <a class="reference internal" href="../ref/settings.html#std:setting-TEMPLATES-OPTIONS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">OPTIONS</span></code></a>.</p>
</li>
<li><p class="first">Initially empty <code class="docutils literal notranslate"><span class="pre">extra</span></code> inlines can now be removed, in the same way as
dynamically created ones.</p>
</li>
<li><p class="first"><code class="docutils literal notranslate"><span class="pre">XRegExp</span></code> is upgraded from version 2.0.0 to 3.2.0.</p>
</li>
<li><p class="first">jQuery is upgraded from version 3.4.1 to 3.5.1.</p>
</li>
<li><p class="first">Select2 library is upgraded from version 4.0.7 to 4.0.13.</p>
</li>
</ul>
</div>
<div class="section" id="s-django-contrib-auth">
<span id="django-contrib-auth"></span><h4><a class="reference internal" href="../topics/auth/index.html#module-django.contrib.auth" title="django.contrib.auth: Django's authentication framework."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.auth</span></code></a><a class="headerlink" href="#django-contrib-auth" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The default iteration count for the PBKDF2 password hasher is increased from
180,000 to 216,000.</li>
<li>The new <a class="reference internal" href="../ref/settings.html#std:setting-PASSWORD_RESET_TIMEOUT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">PASSWORD_RESET_TIMEOUT</span></code></a> setting allows defining the number
of seconds a password reset link is valid for. This is encouraged instead of
the deprecated <code class="docutils literal notranslate"><span class="pre">PASSWORD_RESET_TIMEOUT_DAYS</span></code> setting, which will be removed
in Django 4.0.</li>
<li>The password reset mechanism now uses the SHA-256 hashing algorithm. Support
for tokens that use the old hashing algorithm remains until Django 4.0.</li>
<li><a class="reference internal" href="../topics/auth/customizing.html#django.contrib.auth.models.AbstractBaseUser.get_session_auth_hash" title="django.contrib.auth.models.AbstractBaseUser.get_session_auth_hash"><code class="xref py py-meth docutils literal notranslate"><span class="pre">AbstractBaseUser.get_session_auth_hash()</span></code></a> now uses the SHA-256 hashing
algorithm. Support for user sessions that use the old hashing algorithm
remains until Django 4.0.</li>
</ul>
</div>
<div class="section" id="s-django-contrib-contenttypes">
<span id="django-contrib-contenttypes"></span><h4><a class="reference internal" href="../ref/contrib/contenttypes.html#module-django.contrib.contenttypes" title="django.contrib.contenttypes: Provides generic interface to installed models."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.contenttypes</span></code></a><a class="headerlink" href="#django-contrib-contenttypes" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The new <a class="reference internal" href="../ref/django-admin.html#cmdoption-remove-stale-contenttypes-include-stale-apps"><code class="xref std std-option docutils literal notranslate"><span class="pre">remove_stale_contenttypes</span> <span class="pre">--include-stale-apps</span></code></a> option
allows removing stale content types from previously installed apps that have
been removed from <a class="reference internal" href="../ref/settings.html#std:setting-INSTALLED_APPS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">INSTALLED_APPS</span></code></a>.</li>
</ul>
</div>
<div class="section" id="s-django-contrib-gis">
<span id="django-contrib-gis"></span><h4><a class="reference internal" href="../ref/contrib/gis/index.html#module-django.contrib.gis" title="django.contrib.gis: Geographic Information System (GIS) extensions for Django"><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.gis</span></code></a><a class="headerlink" href="#django-contrib-gis" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../ref/contrib/gis/geoquerysets.html#std:fieldlookup-relate"><code class="xref std std-lookup docutils literal notranslate"><span class="pre">relate</span></code></a> lookup is now supported on MariaDB.</li>
<li>Added the <a class="reference internal" href="../ref/contrib/gis/geos.html#django.contrib.gis.geos.LinearRing.is_counterclockwise" title="django.contrib.gis.geos.LinearRing.is_counterclockwise"><code class="xref py py-attr docutils literal notranslate"><span class="pre">LinearRing.is_counterclockwise</span></code></a> property.</li>
<li><a class="reference internal" href="../ref/contrib/gis/functions.html#django.contrib.gis.db.models.functions.AsGeoJSON" title="django.contrib.gis.db.models.functions.AsGeoJSON"><code class="xref py py-class docutils literal notranslate"><span class="pre">AsGeoJSON</span></code></a> is now supported
on Oracle.</li>
<li>Added the <a class="reference internal" href="../ref/contrib/gis/functions.html#django.contrib.gis.db.models.functions.AsWKB" title="django.contrib.gis.db.models.functions.AsWKB"><code class="xref py py-class docutils literal notranslate"><span class="pre">AsWKB</span></code></a> and
<a class="reference internal" href="../ref/contrib/gis/functions.html#django.contrib.gis.db.models.functions.AsWKT" title="django.contrib.gis.db.models.functions.AsWKT"><code class="xref py py-class docutils literal notranslate"><span class="pre">AsWKT</span></code></a> functions.</li>
<li>Added support for PostGIS 3 and GDAL 3.</li>
</ul>
</div>
<div class="section" id="s-django-contrib-humanize">
<span id="django-contrib-humanize"></span><h4><a class="reference internal" href="../ref/contrib/humanize.html#module-django.contrib.humanize" title="django.contrib.humanize: A set of Django template filters useful for adding a &quot;human touch&quot; to data."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.humanize</span></code></a><a class="headerlink" href="#django-contrib-humanize" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../ref/contrib/humanize.html#std:templatefilter-intword"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">intword</span></code></a> template filter now supports negative integers.</li>
</ul>
</div>
<div class="section" id="s-django-contrib-postgres">
<span id="django-contrib-postgres"></span><h4><a class="reference internal" href="../ref/contrib/postgres/index.html#module-django.contrib.postgres" title="django.contrib.postgres: PostgreSQL-specific fields and features"><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.postgres</span></code></a><a class="headerlink" href="#django-contrib-postgres" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The new <a class="reference internal" href="../ref/contrib/postgres/indexes.html#django.contrib.postgres.indexes.BloomIndex" title="django.contrib.postgres.indexes.BloomIndex"><code class="xref py py-class docutils literal notranslate"><span class="pre">BloomIndex</span></code></a> class allows
creating <code class="docutils literal notranslate"><span class="pre">bloom</span></code> indexes in the database. The new
<a class="reference internal" href="../ref/contrib/postgres/operations.html#django.contrib.postgres.operations.BloomExtension" title="django.contrib.postgres.operations.BloomExtension"><code class="xref py py-class docutils literal notranslate"><span class="pre">BloomExtension</span></code></a> migration
operation installs the <code class="docutils literal notranslate"><span class="pre">bloom</span></code> extension to add support for this index.</li>
<li><a class="reference internal" href="../ref/models/instances.html#django.db.models.Model.get_FOO_display" title="django.db.models.Model.get_FOO_display"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_FOO_display()</span></code></a> now supports
<a class="reference internal" href="../ref/contrib/postgres/fields.html#django.contrib.postgres.fields.ArrayField" title="django.contrib.postgres.fields.ArrayField"><code class="xref py py-class docutils literal notranslate"><span class="pre">ArrayField</span></code></a> and
<a class="reference internal" href="../ref/contrib/postgres/fields.html#django.contrib.postgres.fields.RangeField" title="django.contrib.postgres.fields.RangeField"><code class="xref py py-class docutils literal notranslate"><span class="pre">RangeField</span></code></a>.</li>
<li>The new <a class="reference internal" href="../ref/contrib/postgres/fields.html#std:fieldlookup-rangefield.lower_inc"><code class="xref std std-lookup docutils literal notranslate"><span class="pre">rangefield.lower_inc</span></code></a>, <a class="reference internal" href="../ref/contrib/postgres/fields.html#std:fieldlookup-rangefield.lower_inf"><code class="xref std std-lookup docutils literal notranslate"><span class="pre">rangefield.lower_inf</span></code></a>,
<a class="reference internal" href="../ref/contrib/postgres/fields.html#std:fieldlookup-rangefield.upper_inc"><code class="xref std std-lookup docutils literal notranslate"><span class="pre">rangefield.upper_inc</span></code></a>, and <a class="reference internal" href="../ref/contrib/postgres/fields.html#std:fieldlookup-rangefield.upper_inf"><code class="xref std std-lookup docutils literal notranslate"><span class="pre">rangefield.upper_inf</span></code></a> lookups
allow querying <a class="reference internal" href="../ref/contrib/postgres/fields.html#django.contrib.postgres.fields.RangeField" title="django.contrib.postgres.fields.RangeField"><code class="xref py py-class docutils literal notranslate"><span class="pre">RangeField</span></code></a> by a bound
type.</li>
<li><a class="reference internal" href="../ref/contrib/postgres/fields.html#std:fieldlookup-rangefield.contained_by"><code class="xref std std-lookup docutils literal notranslate"><span class="pre">rangefield.contained_by</span></code></a> now supports
<a class="reference internal" href="../ref/models/fields.html#django.db.models.SmallAutoField" title="django.db.models.SmallAutoField"><code class="xref py py-class docutils literal notranslate"><span class="pre">SmallAutoField</span></code></a>,
<a class="reference internal" href="../ref/models/fields.html#django.db.models.AutoField" title="django.db.models.AutoField"><code class="xref py py-class docutils literal notranslate"><span class="pre">AutoField</span></code></a>,
<a class="reference internal" href="../ref/models/fields.html#django.db.models.BigAutoField" title="django.db.models.BigAutoField"><code class="xref py py-class docutils literal notranslate"><span class="pre">BigAutoField</span></code></a>,
<a class="reference internal" href="../ref/models/fields.html#django.db.models.SmallIntegerField" title="django.db.models.SmallIntegerField"><code class="xref py py-class docutils literal notranslate"><span class="pre">SmallIntegerField</span></code></a>, and
<a class="reference internal" href="../ref/models/fields.html#django.db.models.DecimalField" title="django.db.models.DecimalField"><code class="xref py py-class docutils literal notranslate"><span class="pre">DecimalField</span></code></a>.</li>
<li><a class="reference internal" href="../ref/contrib/postgres/search.html#django.contrib.postgres.search.SearchQuery" title="django.contrib.postgres.search.SearchQuery"><code class="xref py py-class docutils literal notranslate"><span class="pre">SearchQuery</span></code></a> now supports
<code class="docutils literal notranslate"><span class="pre">'websearch'</span></code> search type on PostgreSQL 11+.</li>
<li><a class="reference internal" href="../ref/contrib/postgres/search.html#django.contrib.postgres.search.SearchQuery" title="django.contrib.postgres.search.SearchQuery"><code class="xref py py-class docutils literal notranslate"><span class="pre">SearchQuery.value</span></code></a> now
supports query expressions.</li>
<li>The new <a class="reference internal" href="../ref/contrib/postgres/search.html#django.contrib.postgres.search.SearchHeadline" title="django.contrib.postgres.search.SearchHeadline"><code class="xref py py-class docutils literal notranslate"><span class="pre">SearchHeadline</span></code></a> class allows
highlighting search results.</li>
<li><a class="reference internal" href="../ref/contrib/postgres/search.html#std:fieldlookup-search"><code class="xref std std-lookup docutils literal notranslate"><span class="pre">search</span></code></a> lookup now supports query expressions.</li>
<li>The new <code class="docutils literal notranslate"><span class="pre">cover_density</span></code> parameter of
<a class="reference internal" href="../ref/contrib/postgres/search.html#django.contrib.postgres.search.SearchRank" title="django.contrib.postgres.search.SearchRank"><code class="xref py py-class docutils literal notranslate"><span class="pre">SearchRank</span></code></a> allows ranking by cover
density.</li>
<li>The new <code class="docutils literal notranslate"><span class="pre">normalization</span></code> parameter of
<a class="reference internal" href="../ref/contrib/postgres/search.html#django.contrib.postgres.search.SearchRank" title="django.contrib.postgres.search.SearchRank"><code class="xref py py-class docutils literal notranslate"><span class="pre">SearchRank</span></code></a> allows rank
normalization.</li>
<li>The new <a class="reference internal" href="../ref/contrib/postgres/constraints.html#django.contrib.postgres.constraints.ExclusionConstraint.deferrable" title="django.contrib.postgres.constraints.ExclusionConstraint.deferrable"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ExclusionConstraint.deferrable</span></code></a> attribute allows creating
deferrable exclusion constraints.</li>
</ul>
</div>
<div class="section" id="s-django-contrib-sessions">
<span id="django-contrib-sessions"></span><h4><a class="reference internal" href="../topics/http/sessions.html#module-django.contrib.sessions" title="django.contrib.sessions: Provides session management for Django projects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.sessions</span></code></a><a class="headerlink" href="#django-contrib-sessions" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The <a class="reference internal" href="../ref/settings.html#std:setting-SESSION_COOKIE_SAMESITE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SESSION_COOKIE_SAMESITE</span></code></a> setting now allows <code class="docutils literal notranslate"><span class="pre">'None'</span></code> (string)
value to explicitly state that the cookie is sent with all same-site and
cross-site requests.</li>
</ul>
</div>
<div class="section" id="s-django-contrib-staticfiles">
<span id="django-contrib-staticfiles"></span><h4><a class="reference internal" href="../ref/contrib/staticfiles.html#module-django.contrib.staticfiles" title="django.contrib.staticfiles: An app for handling static files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.staticfiles</span></code></a><a class="headerlink" href="#django-contrib-staticfiles" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The <a class="reference internal" href="../ref/settings.html#std:setting-STATICFILES_DIRS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATICFILES_DIRS</span></code></a> setting now supports <a class="reference external" href="https://docs.python.org/3/library/pathlib.html#pathlib.Path" title="(在 Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a>.</li>
</ul>
</div>
<div class="section" id="s-cache">
<span id="cache"></span><h4>Cache<a class="headerlink" href="#cache" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The <a class="reference internal" href="../topics/http/decorators.html#django.views.decorators.cache.cache_control" title="django.views.decorators.cache.cache_control"><code class="xref py py-func docutils literal notranslate"><span class="pre">cache_control()</span></code></a> decorator and
<a class="reference internal" href="../ref/utils.html#django.utils.cache.patch_cache_control" title="django.utils.cache.patch_cache_control"><code class="xref py py-func docutils literal notranslate"><span class="pre">patch_cache_control()</span></code></a> method now support multiple
field names in the <code class="docutils literal notranslate"><span class="pre">no-cache</span></code> directive for the <code class="docutils literal notranslate"><span class="pre">Cache-Control</span></code> header,
according to <span class="target" id="index-0"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc7234.html#section-5.2.2.2"><strong>RFC 7234#section-5.2.2.2</strong></a>.</li>
<li><a class="reference internal" href="../topics/cache.html#django.core.caches.cache.delete" title="django.core.caches.cache.delete"><code class="xref py py-meth docutils literal notranslate"><span class="pre">delete()</span></code></a> now returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if the key was
successfully deleted, <code class="docutils literal notranslate"><span class="pre">False</span></code> otherwise.</li>
</ul>
</div>
<div class="section" id="s-csrf">
<span id="csrf"></span><h4>CSRF<a class="headerlink" href="#csrf" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The <a class="reference internal" href="../ref/settings.html#std:setting-CSRF_COOKIE_SAMESITE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">CSRF_COOKIE_SAMESITE</span></code></a> setting now allows <code class="docutils literal notranslate"><span class="pre">'None'</span></code> (string)
value to explicitly state that the cookie is sent with all same-site and
cross-site requests.</li>
</ul>
</div>
<div class="section" id="s-email">
<span id="email"></span><h4>Email<a class="headerlink" href="#email" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The <a class="reference internal" href="../ref/settings.html#std:setting-EMAIL_FILE_PATH"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_FILE_PATH</span></code></a> setting, used by the <a class="reference internal" href="../topics/email.html#topic-email-file-backend"><span class="std std-ref">file email backend</span></a>, now supports <a class="reference external" href="https://docs.python.org/3/library/pathlib.html#pathlib.Path" title="(在 Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a>.</li>
</ul>
</div>
<div class="section" id="s-error-reporting">
<span id="error-reporting"></span><h4>Error Reporting<a class="headerlink" href="#error-reporting" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../howto/error-reporting.html#django.views.debug.SafeExceptionReporterFilter" title="django.views.debug.SafeExceptionReporterFilter"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.views.debug.SafeExceptionReporterFilter</span></code></a> now filters sensitive
values from <code class="docutils literal notranslate"><span class="pre">request.META</span></code> in exception reports.</li>
<li>The new <a class="reference internal" href="../howto/error-reporting.html#django.views.debug.SafeExceptionReporterFilter.cleansed_substitute" title="django.views.debug.SafeExceptionReporterFilter.cleansed_substitute"><code class="xref py py-attr docutils literal notranslate"><span class="pre">SafeExceptionReporterFilter.cleansed_substitute</span></code></a> and
<a class="reference internal" href="../howto/error-reporting.html#django.views.debug.SafeExceptionReporterFilter.hidden_settings" title="django.views.debug.SafeExceptionReporterFilter.hidden_settings"><code class="xref py py-attr docutils literal notranslate"><span class="pre">SafeExceptionReporterFilter.hidden_settings</span></code></a> attributes allow
customization of sensitive settings and <code class="docutils literal notranslate"><span class="pre">request.META</span></code> filtering in
exception reports.</li>
<li>The technical 404 debug view now respects
<a class="reference internal" href="../ref/settings.html#std:setting-DEFAULT_EXCEPTION_REPORTER_FILTER"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_EXCEPTION_REPORTER_FILTER</span></code></a> when applying settings
filtering.</li>
<li>The new <a class="reference internal" href="../ref/settings.html#std:setting-DEFAULT_EXCEPTION_REPORTER"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_EXCEPTION_REPORTER</span></code></a> allows providing a
<a class="reference internal" href="../howto/error-reporting.html#django.views.debug.ExceptionReporter" title="django.views.debug.ExceptionReporter"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.views.debug.ExceptionReporter</span></code></a> subclass to customize exception
report generation. See <a class="reference internal" href="../howto/error-reporting.html#custom-error-reports"><span class="std std-ref">自定义错误报告</span></a> for details.</li>
</ul>
</div>
<div class="section" id="s-file-storage">
<span id="file-storage"></span><h4>File Storage<a class="headerlink" href="#file-storage" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">FileSystemStorage.save()</span></code> method now supports <a class="reference external" href="https://docs.python.org/3/library/pathlib.html#pathlib.Path" title="(在 Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a>.</li>
<li><a class="reference internal" href="../ref/models/fields.html#django.db.models.FileField" title="django.db.models.FileField"><code class="xref py py-class docutils literal notranslate"><span class="pre">FileField</span></code></a> and
<a class="reference internal" href="../ref/models/fields.html#django.db.models.ImageField" title="django.db.models.ImageField"><code class="xref py py-class docutils literal notranslate"><span class="pre">ImageField</span></code></a> now accept a callable for <code class="docutils literal notranslate"><span class="pre">storage</span></code>.
This allows you to modify the used storage at runtime, selecting different
storages for different environments, for example.</li>
</ul>
</div>
<div class="section" id="s-forms">
<span id="forms"></span><h4>Forms<a class="headerlink" href="#forms" title="永久链接至标题">¶</a></h4>
<ul>
<li><p class="first"><a class="reference internal" href="../ref/forms/fields.html#django.forms.ModelChoiceIterator" title="django.forms.ModelChoiceIterator"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelChoiceIterator</span></code></a>, used by
<a class="reference internal" href="../ref/forms/fields.html#django.forms.ModelChoiceField" title="django.forms.ModelChoiceField"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelChoiceField</span></code></a> and
<a class="reference internal" href="../ref/forms/fields.html#django.forms.ModelMultipleChoiceField" title="django.forms.ModelMultipleChoiceField"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelMultipleChoiceField</span></code></a>, now uses
<a class="reference internal" href="../ref/forms/fields.html#django.forms.ModelChoiceIteratorValue" title="django.forms.ModelChoiceIteratorValue"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelChoiceIteratorValue</span></code></a> that can be used by widgets
to access model instances. See <a class="reference internal" href="../ref/forms/fields.html#iterating-relationship-choices"><span class="std std-ref">迭代关系选择</span></a> for
details.</p>
</li>
<li><p class="first"><a class="reference internal" href="../ref/forms/fields.html#django.forms.DateTimeField" title="django.forms.DateTimeField"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.forms.DateTimeField</span></code></a> now accepts dates in a subset of ISO 8601
datetime formats, including optional timezone, e.g. <code class="docutils literal notranslate"><span class="pre">2019-10-10T06:47</span></code>,
<code class="docutils literal notranslate"><span class="pre">2019-10-10T06:47:23+04:00</span></code>, or <code class="docutils literal notranslate"><span class="pre">2019-10-10T06:47:23Z</span></code>. The timezone will
always be retained if provided, with timezone-aware datetimes being returned
even when <a class="reference internal" href="../ref/settings.html#std:setting-USE_TZ"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_TZ</span></code></a> is <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
<p>Additionally, <code class="docutils literal notranslate"><span class="pre">DateTimeField</span></code> now uses <code class="docutils literal notranslate"><span class="pre">DATE_INPUT_FORMATS</span></code> in addition
to <code class="docutils literal notranslate"><span class="pre">DATETIME_INPUT_FORMATS</span></code> when converting a field input to a <code class="docutils literal notranslate"><span class="pre">datetime</span></code>
value.</p>
</li>
<li><p class="first"><a class="reference internal" href="../ref/forms/widgets.html#django.forms.MultiWidget.widgets" title="django.forms.MultiWidget.widgets"><code class="xref py py-attr docutils literal notranslate"><span class="pre">MultiWidget.widgets</span></code></a> now accepts a dictionary which allows
customizing subwidget <code class="docutils literal notranslate"><span class="pre">name</span></code> attributes.</p>
</li>
<li><p class="first">The new <a class="reference internal" href="../ref/forms/api.html#django.forms.BoundField.widget_type" title="django.forms.BoundField.widget_type"><code class="xref py py-attr docutils literal notranslate"><span class="pre">BoundField.widget_type</span></code></a> property can be used to dynamically
adjust form rendering based upon the widget type.</p>
</li>
</ul>
</div>
<div class="section" id="s-internationalization">
<span id="internationalization"></span><h4>Internationalization<a class="headerlink" href="#internationalization" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The <a class="reference internal" href="../ref/settings.html#std:setting-LANGUAGE_COOKIE_SAMESITE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_SAMESITE</span></code></a> setting now allows <code class="docutils literal notranslate"><span class="pre">'None'</span></code>
(string) value to explicitly state that the cookie is sent with all same-site
and cross-site requests.</li>
<li>Added support and translations for the Algerian Arabic, Igbo, Kyrgyz, Tajik,
and Turkmen languages.</li>
</ul>
</div>
<div class="section" id="s-management-commands">
<span id="management-commands"></span><h4>Management Commands<a class="headerlink" href="#management-commands" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The new <a class="reference internal" href="../ref/django-admin.html#cmdoption-check-database"><code class="xref std std-option docutils literal notranslate"><span class="pre">check</span> <span class="pre">--database</span></code></a> option allows specifying database aliases
for running the <code class="docutils literal notranslate"><span class="pre">database</span></code> system checks. Previously these checks were
enabled for all configured <a class="reference internal" href="../ref/settings.html#std:setting-DATABASES"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATABASES</span></code></a> by passing the <code class="docutils literal notranslate"><span class="pre">database</span></code>
tag to the command.</li>
<li>The new <a class="reference internal" href="../ref/django-admin.html#cmdoption-migrate-check"><code class="xref std std-option docutils literal notranslate"><span class="pre">migrate</span> <span class="pre">--check</span></code></a> option makes the command exit with a
non-zero status when unapplied migrations are detected.</li>
<li>The new <code class="docutils literal notranslate"><span class="pre">returncode</span></code> argument for
<a class="reference internal" href="../howto/custom-management-commands.html#django.core.management.CommandError" title="django.core.management.CommandError"><code class="xref py py-attr docutils literal notranslate"><span class="pre">CommandError</span></code></a> allows customizing the exit
status for management commands.</li>
<li>The new <a class="reference internal" href="../ref/django-admin.html#cmdoption-dbshell"><code class="xref std std-option docutils literal notranslate"><span class="pre">dbshell</span> <span class="pre">--</span> <span class="pre">ARGUMENTS</span></code></a> option allows passing
extra arguments to the command-line client for the database.</li>
<li>The <a class="reference internal" href="../ref/django-admin.html#django-admin-flush"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">flush</span></code></a> and <a class="reference internal" href="../ref/django-admin.html#django-admin-sqlflush"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">sqlflush</span></code></a> commands now include SQL to
reset sequences on SQLite.</li>
</ul>
</div>
<div class="section" id="s-models">
<span id="models"></span><h4>Models<a class="headerlink" href="#models" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The new <a class="reference internal" href="../ref/models/database-functions.html#django.db.models.functions.ExtractIsoWeekDay" title="django.db.models.functions.ExtractIsoWeekDay"><code class="xref py py-class docutils literal notranslate"><span class="pre">ExtractIsoWeekDay</span></code></a> function
extracts ISO-8601 week days from <a class="reference internal" href="../ref/models/fields.html#django.db.models.DateField" title="django.db.models.DateField"><code class="xref py py-class docutils literal notranslate"><span class="pre">DateField</span></code></a> and
<a class="reference internal" href="../ref/models/fields.html#django.db.models.DateTimeField" title="django.db.models.DateTimeField"><code class="xref py py-class docutils literal notranslate"><span class="pre">DateTimeField</span></code></a>, and the new <a class="reference internal" href="../ref/models/querysets.html#std:fieldlookup-iso_week_day"><code class="xref std std-lookup docutils literal notranslate"><span class="pre">iso_week_day</span></code></a>
lookup allows querying by an ISO-8601 day of week.</li>
<li><a class="reference internal" href="../ref/models/querysets.html#django.db.models.query.QuerySet.explain" title="django.db.models.query.QuerySet.explain"><code class="xref py py-meth docutils literal notranslate"><span class="pre">QuerySet.explain()</span></code></a> now supports:<ul>
<li><code class="docutils literal notranslate"><span class="pre">TREE</span></code> format on MySQL 8.0.16+,</li>
<li><code class="docutils literal notranslate"><span class="pre">analyze</span></code> option on MySQL 8.0.18+ and MariaDB.</li>
</ul>
</li>
<li>Added <a class="reference internal" href="../ref/models/fields.html#django.db.models.PositiveBigIntegerField" title="django.db.models.PositiveBigIntegerField"><code class="xref py py-class docutils literal notranslate"><span class="pre">PositiveBigIntegerField</span></code></a> which acts much like
a <a class="reference internal" href="../ref/models/fields.html#django.db.models.PositiveIntegerField" title="django.db.models.PositiveIntegerField"><code class="xref py py-class docutils literal notranslate"><span class="pre">PositiveIntegerField</span></code></a> except that it only allows
values under a certain (database-dependent) limit. Values from <code class="docutils literal notranslate"><span class="pre">0</span></code> to
<code class="docutils literal notranslate"><span class="pre">9223372036854775807</span></code> are safe in all databases supported by Django.</li>
<li>The new <a class="reference internal" href="../ref/models/fields.html#django.db.models.RESTRICT" title="django.db.models.RESTRICT"><code class="xref py py-class docutils literal notranslate"><span class="pre">RESTRICT</span></code></a> option for
<a class="reference internal" href="../ref/models/fields.html#django.db.models.ForeignKey.on_delete" title="django.db.models.ForeignKey.on_delete"><code class="xref py py-attr docutils literal notranslate"><span class="pre">on_delete</span></code></a> argument of <code class="docutils literal notranslate"><span class="pre">ForeignKey</span></code> and
<code class="docutils literal notranslate"><span class="pre">OneToOneField</span></code> emulates the behavior of the SQL constraint <code class="docutils literal notranslate"><span class="pre">ON</span> <span class="pre">DELETE</span>
<span class="pre">RESTRICT</span></code>.</li>
<li><a class="reference internal" href="../ref/models/constraints.html#django.db.models.CheckConstraint.check" title="django.db.models.CheckConstraint.check"><code class="xref py py-attr docutils literal notranslate"><span class="pre">CheckConstraint.check</span></code></a> now supports boolean expressions.</li>
<li>The <a class="reference internal" href="../ref/models/relations.html#django.db.models.fields.related.RelatedManager.add" title="django.db.models.fields.related.RelatedManager.add"><code class="xref py py-meth docutils literal notranslate"><span class="pre">RelatedManager.add()</span></code></a>, <a class="reference internal" href="../ref/models/relations.html#django.db.models.fields.related.RelatedManager.create" title="django.db.models.fields.related.RelatedManager.create"><code class="xref py py-meth docutils literal notranslate"><span class="pre">create()</span></code></a>, and
<a class="reference internal" href="../ref/models/relations.html#django.db.models.fields.related.RelatedManager.set" title="django.db.models.fields.related.RelatedManager.set"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set()</span></code></a> methods now accept callables as values in the
<code class="docutils literal notranslate"><span class="pre">through_defaults</span></code> argument.</li>
<li>The new <code class="docutils literal notranslate"><span class="pre">is_dst</span></code>  parameter of the <a class="reference internal" href="../ref/models/querysets.html#django.db.models.query.QuerySet.datetimes" title="django.db.models.query.QuerySet.datetimes"><code class="xref py py-meth docutils literal notranslate"><span class="pre">QuerySet.datetimes()</span></code></a> determines
the treatment of nonexistent and ambiguous datetimes.</li>
<li>The new <a class="reference internal" href="../ref/models/expressions.html#django.db.models.F" title="django.db.models.F"><code class="xref py py-class docutils literal notranslate"><span class="pre">F</span></code></a> expression <code class="docutils literal notranslate"><span class="pre">bitxor()</span></code> method allows
<a class="reference internal" href="../topics/db/queries.html#using-f-expressions-in-filters"><span class="std std-ref">bitwise XOR operation</span></a>.</li>
<li><a class="reference internal" href="../ref/models/querysets.html#django.db.models.query.QuerySet.bulk_create" title="django.db.models.query.QuerySet.bulk_create"><code class="xref py py-meth docutils literal notranslate"><span class="pre">QuerySet.bulk_create()</span></code></a> now sets the primary key on objects when using
MariaDB 10.5+.</li>
<li>The <code class="docutils literal notranslate"><span class="pre">DatabaseOperations.sql_flush()</span></code> method now generates more efficient
SQL on MySQL by using <code class="docutils literal notranslate"><span class="pre">DELETE</span></code> instead of <code class="docutils literal notranslate"><span class="pre">TRUNCATE</span></code> statements for
tables which don't require resetting sequences.</li>
<li>SQLite functions are now marked as <a class="reference external" href="https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.create_function" title="(在 Python v3.9)"><code class="xref py py-meth docutils literal notranslate"><span class="pre">deterministic</span></code></a> on Python 3.8+. This allows using them
in check constraints and partial indexes.</li>
<li>The new <a class="reference internal" href="../ref/models/constraints.html#django.db.models.UniqueConstraint.deferrable" title="django.db.models.UniqueConstraint.deferrable"><code class="xref py py-attr docutils literal notranslate"><span class="pre">UniqueConstraint.deferrable</span></code></a> attribute allows creating
deferrable unique constraints.</li>
</ul>
</div>
<div class="section" id="s-pagination">
<span id="pagination"></span><h4>Pagination<a class="headerlink" href="#pagination" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../ref/paginator.html#django.core.paginator.Paginator" title="django.core.paginator.Paginator"><code class="xref py py-class docutils literal notranslate"><span class="pre">Paginator</span></code></a> can now be iterated over to yield
its pages.</li>
</ul>
</div>
<div class="section" id="s-requests-and-responses">
<span id="requests-and-responses"></span><h4>Requests and Responses<a class="headerlink" href="#requests-and-responses" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>If <a class="reference internal" href="../ref/settings.html#std:setting-ALLOWED_HOSTS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">ALLOWED_HOSTS</span></code></a> is empty and <code class="docutils literal notranslate"><span class="pre">DEBUG=True</span></code>, subdomains of
localhost are now allowed in the <code class="docutils literal notranslate"><span class="pre">Host</span></code> header, e.g. <code class="docutils literal notranslate"><span class="pre">static.localhost</span></code>.</li>
<li><a class="reference internal" href="../ref/request-response.html#django.http.HttpResponse.set_cookie" title="django.http.HttpResponse.set_cookie"><code class="xref py py-meth docutils literal notranslate"><span class="pre">HttpResponse.set_cookie()</span></code></a> and <a class="reference internal" href="../ref/request-response.html#django.http.HttpResponse.set_signed_cookie" title="django.http.HttpResponse.set_signed_cookie"><code class="xref py py-meth docutils literal notranslate"><span class="pre">HttpResponse.set_signed_cookie()</span></code></a>
now allow using <code class="docutils literal notranslate"><span class="pre">samesite='None'</span></code> (string) to explicitly state that the
cookie is sent with all same-site and cross-site requests.</li>
<li>The new <a class="reference internal" href="../ref/request-response.html#django.http.HttpRequest.accepts" title="django.http.HttpRequest.accepts"><code class="xref py py-meth docutils literal notranslate"><span class="pre">HttpRequest.accepts()</span></code></a> method returns whether the request
accepts the given MIME type according to the <code class="docutils literal notranslate"><span class="pre">Accept</span></code> HTTP header.</li>
</ul>
</div>
<div class="section" id="s-security">
<span id="s-whats-new-security-3-1"></span><span id="security"></span><span id="whats-new-security-3-1"></span><h4>Security<a class="headerlink" href="#security" title="永久链接至标题">¶</a></h4>
<ul>
<li><p class="first">The <a class="reference internal" href="../ref/settings.html#std:setting-SECURE_REFERRER_POLICY"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_REFERRER_POLICY</span></code></a> setting now defaults to
<code class="docutils literal notranslate"><span class="pre">'same-origin'</span></code>. With this configured,
<a class="reference internal" href="../ref/middleware.html#django.middleware.security.SecurityMiddleware" title="django.middleware.security.SecurityMiddleware"><code class="xref py py-class docutils literal notranslate"><span class="pre">SecurityMiddleware</span></code></a> sets the
<a class="reference internal" href="../ref/middleware.html#referrer-policy"><span class="std std-ref">Referrer 政策</span></a> header to <code class="docutils literal notranslate"><span class="pre">same-origin</span></code> on all responses that do not
already have it. This prevents the <code class="docutils literal notranslate"><span class="pre">Referer</span></code> header being sent to other
origins. If you need the previous behavior, explicitly set
<a class="reference internal" href="../ref/settings.html#std:setting-SECURE_REFERRER_POLICY"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_REFERRER_POLICY</span></code></a> to <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
</li>
<li><p class="first">The default algorithm of <a class="reference internal" href="../topics/signing.html#django.core.signing.Signer" title="django.core.signing.Signer"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.core.signing.Signer</span></code></a>,
<a class="reference internal" href="../topics/signing.html#django.core.signing.loads" title="django.core.signing.loads"><code class="xref py py-meth docutils literal notranslate"><span class="pre">django.core.signing.loads()</span></code></a>, and <a class="reference internal" href="../topics/signing.html#django.core.signing.dumps" title="django.core.signing.dumps"><code class="xref py py-meth docutils literal notranslate"><span class="pre">django.core.signing.dumps()</span></code></a> is
changed to the SHA-256. Support for signatures made with the old SHA-1
algorithm remains until Django 4.0.</p>
<p>Also, the new <code class="docutils literal notranslate"><span class="pre">algorithm</span></code> parameter of the
<a class="reference internal" href="../topics/signing.html#django.core.signing.Signer" title="django.core.signing.Signer"><code class="xref py py-class docutils literal notranslate"><span class="pre">Signer</span></code></a> allows customizing the hashing
algorithm.</p>
</li>
</ul>
</div>
<div class="section" id="s-templates">
<span id="templates"></span><h4>Templates<a class="headerlink" href="#templates" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The renamed <a class="reference internal" href="../topics/i18n/translation.html#std:templatetag-translate"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">translate</span></code></a> and <a class="reference internal" href="../topics/i18n/translation.html#std:templatetag-blocktranslate"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">blocktranslate</span></code></a> template tags are
introduced for internationalization in template code. The older <a class="reference internal" href="../topics/i18n/translation.html#std:templatetag-trans"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">trans</span></code></a>
and <a class="reference internal" href="../topics/i18n/translation.html#std:templatetag-blocktrans"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">blocktrans</span></code></a> template tags aliases continue to work, and will be
retained for the foreseeable future.</li>
<li>The <a class="reference internal" href="../ref/templates/builtins.html#std:templatetag-include"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">include</span></code></a> template tag now accepts iterables of template names.</li>
</ul>
</div>
<div class="section" id="s-tests">
<span id="tests"></span><h4>Tests<a class="headerlink" href="#tests" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../topics/testing/tools.html#django.test.SimpleTestCase" title="django.test.SimpleTestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleTestCase</span></code></a> now implements the <code class="docutils literal notranslate"><span class="pre">debug()</span></code> method to
allow running a test without collecting the result and catching exceptions.
This can be used to support running tests under a debugger.</li>
<li>The new <a class="reference internal" href="../ref/settings.html#std:setting-TEST_MIGRATE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MIGRATE</span></code></a> test database setting allows
disabling of migrations during a test database creation.</li>
<li>Django test runner now supports a <a class="reference internal" href="../ref/django-admin.html#cmdoption-test-buffer"><code class="xref std std-option docutils literal notranslate"><span class="pre">test</span> <span class="pre">--buffer</span></code></a> option to discard
output for passing tests.</li>
<li><a class="reference internal" href="../topics/testing/advanced.html#django.test.runner.DiscoverRunner" title="django.test.runner.DiscoverRunner"><code class="xref py py-class docutils literal notranslate"><span class="pre">DiscoverRunner</span></code></a> now skips running the system
checks on databases not <a class="reference internal" href="../topics/testing/tools.html#testing-multi-db"><span class="std std-ref">referenced by tests</span></a>.</li>
<li><a class="reference internal" href="../topics/testing/tools.html#django.test.TransactionTestCase" title="django.test.TransactionTestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">TransactionTestCase</span></code></a> teardown is now faster on MySQL
due to <a class="reference internal" href="../ref/django-admin.html#django-admin-flush"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">flush</span></code></a> command improvements. As a side effect the latter
doesn't automatically reset sequences on teardown anymore. Enable
<a class="reference internal" href="../topics/testing/advanced.html#django.test.TransactionTestCase.reset_sequences" title="django.test.TransactionTestCase.reset_sequences"><code class="xref py py-attr docutils literal notranslate"><span class="pre">TransactionTestCase.reset_sequences</span></code></a> if your tests require this
feature.</li>
</ul>
</div>
<div class="section" id="s-urls">
<span id="urls"></span><h4>URLs<a class="headerlink" href="#urls" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../topics/http/urls.html#registering-custom-path-converters"><span class="std std-ref">Path converters</span></a> can now raise
<code class="docutils literal notranslate"><span class="pre">ValueError</span></code> in <code class="docutils literal notranslate"><span class="pre">to_url()</span></code> to indicate no match when reversing URLs.</li>
</ul>
</div>
<div class="section" id="s-utilities">
<span id="utilities"></span><h4>Utilities<a class="headerlink" href="#utilities" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../ref/utils.html#django.utils.encoding.filepath_to_uri" title="django.utils.encoding.filepath_to_uri"><code class="xref py py-func docutils literal notranslate"><span class="pre">filepath_to_uri()</span></code></a> now supports
<a class="reference external" href="https://docs.python.org/3/library/pathlib.html#pathlib.Path" title="(在 Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a>.</li>
<li><a class="reference internal" href="../ref/utils.html#django.utils.dateparse.parse_duration" title="django.utils.dateparse.parse_duration"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse_duration()</span></code></a> now supports comma separators
for decimal fractions in the ISO 8601 format.</li>
<li><a class="reference internal" href="../ref/utils.html#django.utils.dateparse.parse_datetime" title="django.utils.dateparse.parse_datetime"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse_datetime()</span></code></a>,
<a class="reference internal" href="../ref/utils.html#django.utils.dateparse.parse_duration" title="django.utils.dateparse.parse_duration"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse_duration()</span></code></a>, and
<a class="reference internal" href="../ref/utils.html#django.utils.dateparse.parse_time" title="django.utils.dateparse.parse_time"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse_time()</span></code></a> now support comma separators for
milliseconds.</li>
</ul>
</div>
<div class="section" id="s-miscellaneous">
<span id="miscellaneous"></span><h4>Miscellaneous<a class="headerlink" href="#miscellaneous" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The SQLite backend now supports <a class="reference external" href="https://docs.python.org/3/library/pathlib.html#pathlib.Path" title="(在 Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a> for the <code class="docutils literal notranslate"><span class="pre">NAME</span></code>
setting.</li>
<li>The <code class="docutils literal notranslate"><span class="pre">settings.py</span></code> generated by the <a class="reference internal" href="../ref/django-admin.html#django-admin-startproject"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">startproject</span></code></a> command now uses
<a class="reference external" href="https://docs.python.org/3/library/pathlib.html#pathlib.Path" title="(在 Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a> instead of <a class="reference external" href="https://docs.python.org/3/library/os.path.html#module-os.path" title="(在 Python v3.9)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a> for building filesystem
paths.</li>
<li>The <a class="reference internal" href="../ref/settings.html#std:setting-DATABASE-TIME_ZONE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TIME_ZONE</span></code></a> setting is now allowed on
databases that support time zones.</li>
</ul>
</div>
</div>
</div>
<div class="section" id="s-backwards-incompatible-changes-in-3-1">
<span id="s-backwards-incompatible-3-1"></span><span id="backwards-incompatible-changes-in-3-1"></span><span id="backwards-incompatible-3-1"></span><h2>Backwards incompatible changes in 3.1<a class="headerlink" href="#backwards-incompatible-changes-in-3-1" title="永久链接至标题">¶</a></h2>
<div class="section" id="s-database-backend-api">
<span id="database-backend-api"></span><h3>Database backend API<a class="headerlink" href="#database-backend-api" title="永久链接至标题">¶</a></h3>
<p>This section describes changes that may be needed in third-party database
backends.</p>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">DatabaseOperations.fetch_returned_insert_columns()</span></code> now requires an
additional <code class="docutils literal notranslate"><span class="pre">returning_params</span></code> argument.</li>
<li><code class="docutils literal notranslate"><span class="pre">connection.timezone</span></code> property is now <code class="docutils literal notranslate"><span class="pre">'UTC'</span></code> by default, or the
<a class="reference internal" href="../ref/settings.html#std:setting-DATABASE-TIME_ZONE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TIME_ZONE</span></code></a> when <a class="reference internal" href="../ref/settings.html#std:setting-USE_TZ"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_TZ</span></code></a> is <code class="docutils literal notranslate"><span class="pre">True</span></code>
on databases that support time zones. Previously, it was <code class="docutils literal notranslate"><span class="pre">None</span></code> on
databases that support time zones.</li>
<li><code class="docutils literal notranslate"><span class="pre">connection._nodb_connection</span></code> property is changed to the
<code class="docutils literal notranslate"><span class="pre">connection._nodb_cursor()</span></code> method and now returns a context manager that
yields a cursor and automatically closes the cursor and connection upon
exiting the <code class="docutils literal notranslate"><span class="pre">with</span></code> statement.</li>
<li><code class="docutils literal notranslate"><span class="pre">DatabaseClient.runshell()</span></code> now requires an additional <code class="docutils literal notranslate"><span class="pre">parameters</span></code>
argument as a list of extra arguments to pass on to the command-line client.</li>
<li>The <code class="docutils literal notranslate"><span class="pre">sequences</span></code> positional argument of <code class="docutils literal notranslate"><span class="pre">DatabaseOperations.sql_flush()</span></code>
is replaced by the boolean keyword-only argument <code class="docutils literal notranslate"><span class="pre">reset_sequences</span></code>. If
<code class="docutils literal notranslate"><span class="pre">True</span></code>, the sequences of the truncated tables will be reset.</li>
<li>The <code class="docutils literal notranslate"><span class="pre">allow_cascade</span></code> argument of <code class="docutils literal notranslate"><span class="pre">DatabaseOperations.sql_flush()</span></code> is now a
keyword-only argument.</li>
<li>The <code class="docutils literal notranslate"><span class="pre">using</span></code> positional argument of
<code class="docutils literal notranslate"><span class="pre">DatabaseOperations.execute_sql_flush()</span></code> is removed. The method now uses
the database of the called instance.</li>
<li>Third-party database backends must implement support for <code class="docutils literal notranslate"><span class="pre">JSONField</span></code> or set
<code class="docutils literal notranslate"><span class="pre">DatabaseFeatures.supports_json_field</span></code> to <code class="docutils literal notranslate"><span class="pre">False</span></code>. If storing primitives
is not supported, set <code class="docutils literal notranslate"><span class="pre">DatabaseFeatures.supports_primitives_in_json_field</span></code>
to <code class="docutils literal notranslate"><span class="pre">False</span></code>. If there is a true datatype for JSON, set
<code class="docutils literal notranslate"><span class="pre">DatabaseFeatures.has_native_json_field</span></code> to <code class="docutils literal notranslate"><span class="pre">True</span></code>. If
<a class="reference internal" href="../topics/db/queries.html#std:fieldlookup-jsonfield.contains"><code class="xref std std-lookup docutils literal notranslate"><span class="pre">jsonfield.contains</span></code></a> and <a class="reference internal" href="../topics/db/queries.html#std:fieldlookup-jsonfield.contained_by"><code class="xref std std-lookup docutils literal notranslate"><span class="pre">jsonfield.contained_by</span></code></a> are not
supported, set <code class="docutils literal notranslate"><span class="pre">DatabaseFeatures.supports_json_field_contains</span></code> to
<code class="docutils literal notranslate"><span class="pre">False</span></code>.</li>
<li>Third party database backends must implement introspection for <code class="docutils literal notranslate"><span class="pre">JSONField</span></code>
or set <code class="docutils literal notranslate"><span class="pre">can_introspect_json_field</span></code> to <code class="docutils literal notranslate"><span class="pre">False</span></code>.</li>
</ul>
</div>
<div class="section" id="s-dropped-support-for-mariadb-10-1">
<span id="dropped-support-for-mariadb-10-1"></span><h3>Dropped support for MariaDB 10.1<a class="headerlink" href="#dropped-support-for-mariadb-10-1" title="永久链接至标题">¶</a></h3>
<p>Upstream support for MariaDB 10.1 ends in October 2020. Django 3.1 supports
MariaDB 10.2 and higher.</p>
</div>
<div class="section" id="s-contrib-admin-browser-support">
<span id="contrib-admin-browser-support"></span><h3><code class="docutils literal notranslate"><span class="pre">contrib.admin</span></code> browser support<a class="headerlink" href="#contrib-admin-browser-support" title="永久链接至标题">¶</a></h3>
<p>The admin no longer supports the legacy Internet Explorer browser. See
<a class="reference internal" href="../faq/admin.html#admin-browser-support"><span class="std std-ref">the admin FAQ</span></a> for details on supported browsers.</p>
</div>
<div class="section" id="s-abstractuser-first-name-max-length-increased-to-150">
<span id="abstractuser-first-name-max-length-increased-to-150"></span><h3><a class="reference internal" href="../ref/contrib/auth.html#django.contrib.auth.models.User.first_name" title="django.contrib.auth.models.User.first_name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">AbstractUser.first_name</span></code></a> <code class="docutils literal notranslate"><span class="pre">max_length</span></code> increased to 150<a class="headerlink" href="#abstractuser-first-name-max-length-increased-to-150" title="永久链接至标题">¶</a></h3>
<p>A migration for <a class="reference internal" href="../ref/contrib/auth.html#django.contrib.auth.models.User.first_name" title="django.contrib.auth.models.User.first_name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">django.contrib.auth.models.User.first_name</span></code></a> is included.
If you have a custom user model inheriting from <code class="docutils literal notranslate"><span class="pre">AbstractUser</span></code>, you'll need
to generate and apply a database migration for your user model.</p>
<p>If you want to preserve the 30 character limit for first names, use a custom
form:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django</span> <span class="kn">import</span> <span class="n">forms</span>
<span class="kn">from</span> <span class="nn">django.contrib.auth.forms</span> <span class="kn">import</span> <span class="n">UserChangeForm</span>

<span class="k">class</span> <span class="nc">MyUserChangeForm</span><span class="p">(</span><span class="n">UserChangeForm</span><span class="p">):</span>
    <span class="n">first_name</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">30</span><span class="p">,</span> <span class="n">required</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
</pre></div>
</div>
<p>If you wish to keep this restriction in the admin when editing users, set
<code class="docutils literal notranslate"><span class="pre">UserAdmin.form</span></code> to use this form:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.contrib.auth.admin</span> <span class="kn">import</span> <span class="n">UserAdmin</span>
<span class="kn">from</span> <span class="nn">django.contrib.auth.models</span> <span class="kn">import</span> <span class="n">User</span>

<span class="k">class</span> <span class="nc">MyUserAdmin</span><span class="p">(</span><span class="n">UserAdmin</span><span class="p">):</span>
    <span class="n">form</span> <span class="o">=</span> <span class="n">MyUserChangeForm</span>

<span class="n">admin</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">unregister</span><span class="p">(</span><span class="n">User</span><span class="p">)</span>
<span class="n">admin</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">User</span><span class="p">,</span> <span class="n">MyUserAdmin</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="s-id1">
<span id="id1"></span><h3>Miscellaneous<a class="headerlink" href="#id1" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li>The cache keys used by <a class="reference internal" href="../topics/cache.html#std:templatetag-cache"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">cache</span></code></a> and generated by
<a class="reference internal" href="../topics/cache.html#django.core.cache.utils.make_template_fragment_key" title="django.core.cache.utils.make_template_fragment_key"><code class="xref py py-func docutils literal notranslate"><span class="pre">make_template_fragment_key()</span></code></a> are different
from the keys generated by older versions of Django. After upgrading to
Django 3.1, the first request to any previously cached template fragment will
be a cache miss.</li>
<li>The logic behind the decision to return a redirection fallback or a 204 HTTP
response from the <a class="reference internal" href="../topics/i18n/translation.html#django.views.i18n.set_language" title="django.views.i18n.set_language"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_language()</span></code></a> view is now based
on the <code class="docutils literal notranslate"><span class="pre">Accept</span></code> HTTP header instead of the <code class="docutils literal notranslate"><span class="pre">X-Requested-With</span></code> HTTP header
presence.</li>
<li>The compatibility imports of <code class="docutils literal notranslate"><span class="pre">django.core.exceptions.EmptyResultSet</span></code> in
<code class="docutils literal notranslate"><span class="pre">django.db.models.query</span></code>, <code class="docutils literal notranslate"><span class="pre">django.db.models.sql</span></code>, and
<code class="docutils literal notranslate"><span class="pre">django.db.models.sql.datastructures</span></code> are removed.</li>
<li>The compatibility import of <code class="docutils literal notranslate"><span class="pre">django.core.exceptions.FieldDoesNotExist</span></code> in
<code class="docutils literal notranslate"><span class="pre">django.db.models.fields</span></code> is removed.</li>
<li>The compatibility imports of <code class="docutils literal notranslate"><span class="pre">django.forms.utils.pretty_name()</span></code> and
<code class="docutils literal notranslate"><span class="pre">django.forms.boundfield.BoundField</span></code> in <code class="docutils literal notranslate"><span class="pre">django.forms.forms</span></code> are removed.</li>
<li>The compatibility imports of <code class="docutils literal notranslate"><span class="pre">Context</span></code>, <code class="docutils literal notranslate"><span class="pre">ContextPopException</span></code>, and
<code class="docutils literal notranslate"><span class="pre">RequestContext</span></code> in <code class="docutils literal notranslate"><span class="pre">django.template.base</span></code> are removed.</li>
<li>The compatibility import of
<code class="docutils literal notranslate"><span class="pre">django.contrib.admin.helpers.ACTION_CHECKBOX_NAME</span></code> in
<code class="docutils literal notranslate"><span class="pre">django.contrib.admin</span></code> is removed.</li>
<li>The <a class="reference internal" href="../ref/settings.html#std:setting-STATIC_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_URL</span></code></a> and <a class="reference internal" href="../ref/settings.html#std:setting-MEDIA_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MEDIA_URL</span></code></a> settings set to relative
paths are now prefixed by the server-provided value of <code class="docutils literal notranslate"><span class="pre">SCRIPT_NAME</span></code> (or
<code class="docutils literal notranslate"><span class="pre">/</span></code> if not set). This change should not affect settings set to valid URLs
or absolute paths.</li>
<li><a class="reference internal" href="../ref/middleware.html#django.middleware.http.ConditionalGetMiddleware" title="django.middleware.http.ConditionalGetMiddleware"><code class="xref py py-class docutils literal notranslate"><span class="pre">ConditionalGetMiddleware</span></code></a> no longer adds the
<code class="docutils literal notranslate"><span class="pre">ETag</span></code> header to responses with an empty
<a class="reference internal" href="../ref/request-response.html#django.http.HttpResponse.content" title="django.http.HttpResponse.content"><code class="xref py py-attr docutils literal notranslate"><span class="pre">content</span></code></a>.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.utils.decorators.classproperty()</span></code> decorator is made public and
moved to <a class="reference internal" href="../ref/utils.html#django.utils.functional.classproperty" title="django.utils.functional.classproperty"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.utils.functional.classproperty()</span></code></a>.</li>
<li><a class="reference internal" href="../ref/templates/builtins.html#std:templatefilter-floatformat"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">floatformat</span></code></a> template filter now outputs (positive) <code class="docutils literal notranslate"><span class="pre">0</span></code> for
negative numbers which round to zero.</li>
<li><a class="reference internal" href="../ref/models/options.html#django.db.models.Options.ordering" title="django.db.models.Options.ordering"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Meta.ordering</span></code></a> and
<a class="reference internal" href="../ref/models/options.html#django.db.models.Options.unique_together" title="django.db.models.Options.unique_together"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Meta.unique_together</span></code></a>
options on models in <code class="docutils literal notranslate"><span class="pre">django.contrib</span></code> modules that were formerly tuples are
now lists.</li>
<li>The admin calendar widget now handles two-digit years according to the Open
Group Specification, i.e. values between 69 and 99 are mapped to the previous
century, and values between 0 and 68 are mapped to the current century.</li>
<li>Date-only formats are removed from the default list for
<a class="reference internal" href="../ref/settings.html#std:setting-DATETIME_INPUT_FORMATS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATETIME_INPUT_FORMATS</span></code></a>.</li>
<li>The <a class="reference internal" href="../ref/forms/widgets.html#django.forms.FileInput" title="django.forms.FileInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">FileInput</span></code></a> widget no longer renders with the
<code class="docutils literal notranslate"><span class="pre">required</span></code> HTML attribute when initial data exists.</li>
<li>The undocumented <code class="docutils literal notranslate"><span class="pre">django.views.debug.ExceptionReporterFilter</span></code> class is
removed. As per the <a class="reference internal" href="../howto/error-reporting.html#custom-error-reports"><span class="std std-ref">自定义错误报告</span></a> documentation, classes to be
used with <a class="reference internal" href="../ref/settings.html#std:setting-DEFAULT_EXCEPTION_REPORTER_FILTER"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_EXCEPTION_REPORTER_FILTER</span></code></a> need to inherit from
<a class="reference internal" href="../howto/error-reporting.html#django.views.debug.SafeExceptionReporterFilter" title="django.views.debug.SafeExceptionReporterFilter"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.views.debug.SafeExceptionReporterFilter</span></code></a>.</li>
<li>The cache timeout set by <a class="reference internal" href="../topics/cache.html#django.views.decorators.cache.cache_page" title="django.views.decorators.cache.cache_page"><code class="xref py py-func docutils literal notranslate"><span class="pre">cache_page()</span></code></a>
decorator now takes precedence over the <code class="docutils literal notranslate"><span class="pre">max-age</span></code> directive from the
<code class="docutils literal notranslate"><span class="pre">Cache-Control</span></code> header.</li>
<li>Providing a non-local remote field in the <a class="reference internal" href="../ref/models/fields.html#django.db.models.ForeignKey.to_field" title="django.db.models.ForeignKey.to_field"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ForeignKey.to_field</span></code></a>
argument now raises <a class="reference internal" href="../ref/exceptions.html#django.core.exceptions.FieldError" title="django.core.exceptions.FieldError"><code class="xref py py-class docutils literal notranslate"><span class="pre">FieldError</span></code></a>.</li>
<li><a class="reference internal" href="../ref/settings.html#std:setting-SECURE_REFERRER_POLICY"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_REFERRER_POLICY</span></code></a> now defaults to <code class="docutils literal notranslate"><span class="pre">'same-origin'</span></code>. See the
<em>What's New</em> <a class="reference internal" href="#whats-new-security-3-1"><span class="std std-ref">Security section</span></a> above for more
details.</li>
<li><a class="reference internal" href="../ref/django-admin.html#django-admin-check"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">check</span></code></a> management command now runs the <code class="docutils literal notranslate"><span class="pre">database</span></code> system checks
only for database aliases specified using <a class="reference internal" href="../ref/django-admin.html#cmdoption-check-database"><code class="xref std std-option docutils literal notranslate"><span class="pre">check</span> <span class="pre">--database</span></code></a> option.</li>
<li><a class="reference internal" href="../ref/django-admin.html#django-admin-migrate"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">migrate</span></code></a> management command now runs the <code class="docutils literal notranslate"><span class="pre">database</span></code> system checks
only for a database to migrate.</li>
<li>The admin CSS classes <code class="docutils literal notranslate"><span class="pre">row1</span></code> and <code class="docutils literal notranslate"><span class="pre">row2</span></code> are removed in favor of
<code class="docutils literal notranslate"><span class="pre">:nth-child(odd)</span></code> and <code class="docutils literal notranslate"><span class="pre">:nth-child(even)</span></code> pseudo-classes.</li>
<li>The <a class="reference internal" href="../topics/auth/passwords.html#django.contrib.auth.hashers.make_password" title="django.contrib.auth.hashers.make_password"><code class="xref py py-func docutils literal notranslate"><span class="pre">make_password()</span></code></a> function now requires
its argument to be a string or bytes. Other types should be explicitly cast
to one of these.</li>
<li>The undocumented <code class="docutils literal notranslate"><span class="pre">version</span></code> parameter to the
<a class="reference internal" href="../ref/contrib/gis/functions.html#django.contrib.gis.db.models.functions.AsKML" title="django.contrib.gis.db.models.functions.AsKML"><code class="xref py py-class docutils literal notranslate"><span class="pre">AsKML</span></code></a> function is removed.</li>
<li><a class="reference internal" href="../topics/serialization.html#serialization-formats"><span class="std std-ref">JSON and YAML serializers</span></a>, used by
<a class="reference internal" href="../ref/django-admin.html#django-admin-dumpdata"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">dumpdata</span></code></a>, now dump all data with Unicode by default. If you need
the previous behavior, pass <code class="docutils literal notranslate"><span class="pre">ensure_ascii=True</span></code> to JSON serializer, or
<code class="docutils literal notranslate"><span class="pre">allow_unicode=False</span></code> to YAML serializer.</li>
<li>The auto-reloader no longer monitors changes in built-in Django translation
files.</li>
<li>The minimum supported version of <code class="docutils literal notranslate"><span class="pre">mysqlclient</span></code> is increased from 1.3.13 to
1.4.0.</li>
<li>The undocumented <code class="docutils literal notranslate"><span class="pre">django.contrib.postgres.forms.InvalidJSONInput</span></code> and
<code class="docutils literal notranslate"><span class="pre">django.contrib.postgres.forms.JSONString</span></code> are moved to
<code class="docutils literal notranslate"><span class="pre">django.forms.fields</span></code>.</li>
<li>The undocumented <code class="docutils literal notranslate"><span class="pre">django.contrib.postgres.fields.jsonb.JsonAdapter</span></code> class
is removed.</li>
<li>The <a class="reference internal" href="../topics/i18n/formatting.html#std:templatetag-localize"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">{%</span> <span class="pre">localize</span> <span class="pre">off</span> <span class="pre">%}</span></code></a> tag and <a class="reference internal" href="../topics/i18n/formatting.html#std:templatefilter-unlocalize"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">unlocalize</span></code></a>
filter no longer respect <a class="reference internal" href="../ref/settings.html#std:setting-DECIMAL_SEPARATOR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DECIMAL_SEPARATOR</span></code></a> setting.</li>
<li>The minimum supported version of <code class="docutils literal notranslate"><span class="pre">asgiref</span></code> is increased from 3.2 to
3.2.10.</li>
<li>The <a class="reference internal" href="../topics/forms/media.html"><span class="doc">Media</span></a> class now renders <code class="docutils literal notranslate"><span class="pre">&lt;script&gt;</span></code> tags
without the <code class="docutils literal notranslate"><span class="pre">type</span></code> attribute to follow <a class="reference external" href="https://html.spec.whatwg.org/multipage/scripting.html#the-script-element">WHATWG recommendations</a>.</li>
<li><a class="reference internal" href="../ref/forms/fields.html#django.forms.ModelChoiceIterator" title="django.forms.ModelChoiceIterator"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelChoiceIterator</span></code></a>, used by
<a class="reference internal" href="../ref/forms/fields.html#django.forms.ModelChoiceField" title="django.forms.ModelChoiceField"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelChoiceField</span></code></a> and
<a class="reference internal" href="../ref/forms/fields.html#django.forms.ModelMultipleChoiceField" title="django.forms.ModelMultipleChoiceField"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelMultipleChoiceField</span></code></a>, now yields 2-tuple choices
containing <a class="reference internal" href="../ref/forms/fields.html#django.forms.ModelChoiceIteratorValue" title="django.forms.ModelChoiceIteratorValue"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelChoiceIteratorValue</span></code></a> instances as the
first <code class="docutils literal notranslate"><span class="pre">value</span></code> element in each choice. In most cases this proxies
transparently, but if you need the <code class="docutils literal notranslate"><span class="pre">field</span></code> value itself, use the
<a class="reference internal" href="../ref/forms/fields.html#django.forms.ModelChoiceIteratorValue.value" title="django.forms.ModelChoiceIteratorValue.value"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ModelChoiceIteratorValue.value</span></code></a> attribute instead.</li>
</ul>
</div>
</div>
<div class="section" id="s-features-deprecated-in-3-1">
<span id="s-deprecated-features-3-1"></span><span id="features-deprecated-in-3-1"></span><span id="deprecated-features-3-1"></span><h2>Features deprecated in 3.1<a class="headerlink" href="#features-deprecated-in-3-1" title="永久链接至标题">¶</a></h2>
<div class="section" id="s-postgresql-jsonfield">
<span id="s-deprecated-jsonfield"></span><span id="postgresql-jsonfield"></span><span id="deprecated-jsonfield"></span><h3>PostgreSQL <code class="docutils literal notranslate"><span class="pre">JSONField</span></code><a class="headerlink" href="#postgresql-jsonfield" title="永久链接至标题">¶</a></h3>
<p><code class="docutils literal notranslate"><span class="pre">django.contrib.postgres.fields.JSONField</span></code> and
<code class="docutils literal notranslate"><span class="pre">django.contrib.postgres.forms.JSONField</span></code> are deprecated in favor of
<a class="reference internal" href="../ref/models/fields.html#django.db.models.JSONField" title="django.db.models.JSONField"><code class="xref py py-class docutils literal notranslate"><span class="pre">models.JSONField</span></code></a> and
<a class="reference internal" href="../ref/forms/fields.html#django.forms.JSONField" title="django.forms.JSONField"><code class="xref py py-class docutils literal notranslate"><span class="pre">forms.JSONField</span></code></a>.</p>
<p>The undocumented <code class="docutils literal notranslate"><span class="pre">django.contrib.postgres.fields.jsonb.KeyTransform</span></code> and
<code class="docutils literal notranslate"><span class="pre">django.contrib.postgres.fields.jsonb.KeyTextTransform</span></code> are also deprecated
in favor of the transforms in <code class="docutils literal notranslate"><span class="pre">django.db.models.fields.json</span></code>.</p>
<p>The new <code class="docutils literal notranslate"><span class="pre">JSONField</span></code>s, <code class="docutils literal notranslate"><span class="pre">KeyTransform</span></code>, and <code class="docutils literal notranslate"><span class="pre">KeyTextTransform</span></code> can be used
on all supported database backends.</p>
</div>
<div class="section" id="s-id2">
<span id="id2"></span><h3>Miscellaneous<a class="headerlink" href="#id2" title="永久链接至标题">¶</a></h3>
<ul>
<li><p class="first"><code class="docutils literal notranslate"><span class="pre">PASSWORD_RESET_TIMEOUT_DAYS</span></code> setting is deprecated in favor of
<a class="reference internal" href="../ref/settings.html#std:setting-PASSWORD_RESET_TIMEOUT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">PASSWORD_RESET_TIMEOUT</span></code></a>.</p>
</li>
<li><p class="first">The undocumented usage of the <a class="reference internal" href="../ref/models/querysets.html#std:fieldlookup-isnull"><code class="xref std std-lookup docutils literal notranslate"><span class="pre">isnull</span></code></a> lookup with non-boolean values
as the right-hand side is deprecated, use <code class="docutils literal notranslate"><span class="pre">True</span></code> or <code class="docutils literal notranslate"><span class="pre">False</span></code> instead.</p>
</li>
<li><p class="first">The barely documented <code class="docutils literal notranslate"><span class="pre">django.db.models.query_utils.InvalidQuery</span></code> exception
class is deprecated in favor of
<a class="reference internal" href="../ref/exceptions.html#django.core.exceptions.FieldDoesNotExist" title="django.core.exceptions.FieldDoesNotExist"><code class="xref py py-class docutils literal notranslate"><span class="pre">FieldDoesNotExist</span></code></a> and
<a class="reference internal" href="../ref/exceptions.html#django.core.exceptions.FieldError" title="django.core.exceptions.FieldError"><code class="xref py py-class docutils literal notranslate"><span class="pre">FieldError</span></code></a>.</p>
</li>
<li><p class="first">The <code class="docutils literal notranslate"><span class="pre">django-admin.py</span></code> entry point is deprecated in favor of
<code class="docutils literal notranslate"><span class="pre">django-admin</span></code>.</p>
</li>
<li><p class="first">The <code class="docutils literal notranslate"><span class="pre">HttpRequest.is_ajax()</span></code> method is deprecated as it relied on a
jQuery-specific way of signifying AJAX calls, while current usage tends to
use the JavaScript <a class="reference external" href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">Fetch API</a>. Depending on
your use case, you can either write your own AJAX detection method, or use
the new <a class="reference internal" href="../ref/request-response.html#django.http.HttpRequest.accepts" title="django.http.HttpRequest.accepts"><code class="xref py py-meth docutils literal notranslate"><span class="pre">HttpRequest.accepts()</span></code></a> method if your code depends on the
client <code class="docutils literal notranslate"><span class="pre">Accept</span></code> HTTP header.</p>
<p>If you are writing your own AJAX detection method, <code class="docutils literal notranslate"><span class="pre">request.is_ajax()</span></code> can
be reproduced exactly as
<code class="docutils literal notranslate"><span class="pre">request.headers.get('x-requested-with')</span> <span class="pre">==</span> <span class="pre">'XMLHttpRequest'</span></code>.</p>
</li>
<li><p class="first">Passing <code class="docutils literal notranslate"><span class="pre">None</span></code> as the first argument to
<code class="docutils literal notranslate"><span class="pre">django.utils.deprecation.MiddlewareMixin.__init__()</span></code> is deprecated.</p>
</li>
<li><p class="first">The encoding format of cookies values used by
<a class="reference internal" href="../ref/contrib/messages.html#django.contrib.messages.storage.cookie.CookieStorage" title="django.contrib.messages.storage.cookie.CookieStorage"><code class="xref py py-class docutils literal notranslate"><span class="pre">CookieStorage</span></code></a> is different
from the format generated by older versions of Django. Support for the old
format remains until Django 4.0.</p>
</li>
<li><p class="first">The encoding format of sessions is different from the format generated by
older versions of Django. Support for the old format remains until Django
4.0.</p>
</li>
<li><p class="first">The purely documentational <code class="docutils literal notranslate"><span class="pre">providing_args</span></code> argument for
<a class="reference internal" href="../topics/signals.html#django.dispatch.Signal" title="django.dispatch.Signal"><code class="xref py py-class docutils literal notranslate"><span class="pre">Signal</span></code></a> is deprecated. If you rely on this
argument as documentation, you can move the text to a code comment or
docstring.</p>
</li>
<li><p class="first">Calling <code class="docutils literal notranslate"><span class="pre">django.utils.crypto.get_random_string()</span></code> without a <code class="docutils literal notranslate"><span class="pre">length</span></code>
argument is deprecated.</p>
</li>
<li><p class="first">The <code class="docutils literal notranslate"><span class="pre">list</span></code> message for <a class="reference internal" href="../ref/forms/fields.html#django.forms.ModelMultipleChoiceField" title="django.forms.ModelMultipleChoiceField"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelMultipleChoiceField</span></code></a> is
deprecated in favor of <code class="docutils literal notranslate"><span class="pre">invalid_list</span></code>.</p>
</li>
<li><p class="first">Passing raw column aliases to <a class="reference internal" href="../ref/models/querysets.html#django.db.models.query.QuerySet.order_by" title="django.db.models.query.QuerySet.order_by"><code class="xref py py-meth docutils literal notranslate"><span class="pre">QuerySet.order_by()</span></code></a> is deprecated. The
same result can be achieved by passing aliases in a
<a class="reference internal" href="../ref/models/expressions.html#django.db.models.expressions.RawSQL" title="django.db.models.expressions.RawSQL"><code class="xref py py-class docutils literal notranslate"><span class="pre">RawSQL</span></code></a> instead beforehand.</p>
</li>
<li><p class="first">The <code class="docutils literal notranslate"><span class="pre">NullBooleanField</span></code> model field is deprecated in favor of
<code class="docutils literal notranslate"><span class="pre">BooleanField(null=True)</span></code>.</p>
</li>
<li><p class="first"><code class="docutils literal notranslate"><span class="pre">django.conf.urls.url()</span></code> alias of <a class="reference internal" href="../ref/urls.html#django.urls.re_path" title="django.urls.re_path"><code class="xref py py-func docutils literal notranslate"><span class="pre">django.urls.re_path()</span></code></a> is
deprecated.</p>
</li>
<li><p class="first">The <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">ifequal</span> <span class="pre">%}</span></code> and <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">ifnotequal</span> <span class="pre">%}</span></code> template tags are deprecated
in favor of <a class="reference internal" href="../ref/templates/builtins.html#std:templatetag-if"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">{%</span> <span class="pre">if</span> <span class="pre">%}</span></code></a>. <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">if</span> <span class="pre">%}</span></code> covers all use cases, but if
you need to continue using these tags, they can be extracted from Django to a
module and included as a built-in tag in the <a class="reference internal" href="../topics/templates.html#django.template.backends.django.DjangoTemplates" title="django.template.backends.django.DjangoTemplates"><code class="xref py py-class docutils literal notranslate"><span class="pre">'builtins'</span></code></a> option in
<a class="reference internal" href="../ref/settings.html#std:setting-TEMPLATES-OPTIONS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">OPTIONS</span></code></a>.</p>
</li>
<li><p class="first"><code class="docutils literal notranslate"><span class="pre">DEFAULT_HASHING_ALGORITHM</span></code> transitional setting is deprecated.</p>
</li>
</ul>
</div>
</div>
<div class="section" id="s-features-removed-in-3-1">
<span id="s-removed-features-3-1"></span><span id="features-removed-in-3-1"></span><span id="removed-features-3-1"></span><h2>Features removed in 3.1<a class="headerlink" href="#features-removed-in-3-1" title="永久链接至标题">¶</a></h2>
<p>These features have reached the end of their deprecation cycle and are removed
in Django 3.1.</p>
<p>See <a class="reference internal" href="2.2.html#deprecated-features-2-2"><span class="std std-ref">Features deprecated in 2.2</span></a> for details on these changes, including how
to remove usage of these features.</p>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">django.utils.timezone.FixedOffset</span></code> is removed.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.core.paginator.QuerySetPaginator</span></code> is removed.</li>
<li>A model's <code class="docutils literal notranslate"><span class="pre">Meta.ordering</span></code> doesn't affect <code class="docutils literal notranslate"><span class="pre">GROUP</span> <span class="pre">BY</span></code> queries.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.contrib.postgres.fields.FloatRangeField</span></code> and
<code class="docutils literal notranslate"><span class="pre">django.contrib.postgres.forms.FloatRangeField</span></code> are removed.</li>
<li>The <code class="docutils literal notranslate"><span class="pre">FILE_CHARSET</span></code> setting is removed.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.contrib.staticfiles.storage.CachedStaticFilesStorage</span></code> is removed.</li>
<li>The <code class="docutils literal notranslate"><span class="pre">RemoteUserBackend.configure_user()</span></code> method requires <code class="docutils literal notranslate"><span class="pre">request</span></code> as the
first positional argument.</li>
<li>Support for <code class="docutils literal notranslate"><span class="pre">SimpleTestCase.allow_database_queries</span></code> and
<code class="docutils literal notranslate"><span class="pre">TransactionTestCase.multi_db</span></code> is removed.</li>
</ul>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Django 3.1 release notes</a><ul>
<li><a class="reference internal" href="#python-compatibility">Python compatibility</a></li>
<li><a class="reference internal" href="#what-s-new-in-django-3-1">What's new in Django 3.1</a><ul>
<li><a class="reference internal" href="#asynchronous-views-and-middleware-support">Asynchronous views and middleware support</a></li>
<li><a class="reference internal" href="#jsonfield-for-all-supported-database-backends">JSONField for all supported database backends</a></li>
<li><a class="reference internal" href="#default-hashing-algorithm-settings"><code class="docutils literal notranslate"><span class="pre">DEFAULT_HASHING_ALGORITHM</span></code> settings</a></li>
<li><a class="reference internal" href="#minor-features">Minor features</a><ul>
<li><a class="reference internal" href="#django-contrib-admin"><code class="docutils literal notranslate"><span class="pre">django.contrib.admin</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-auth"><code class="docutils literal notranslate"><span class="pre">django.contrib.auth</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-contenttypes"><code class="docutils literal notranslate"><span class="pre">django.contrib.contenttypes</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-gis"><code class="docutils literal notranslate"><span class="pre">django.contrib.gis</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-humanize"><code class="docutils literal notranslate"><span class="pre">django.contrib.humanize</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-postgres"><code class="docutils literal notranslate"><span class="pre">django.contrib.postgres</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-sessions"><code class="docutils literal notranslate"><span class="pre">django.contrib.sessions</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-staticfiles"><code class="docutils literal notranslate"><span class="pre">django.contrib.staticfiles</span></code></a></li>
<li><a class="reference internal" href="#cache">Cache</a></li>
<li><a class="reference internal" href="#csrf">CSRF</a></li>
<li><a class="reference internal" href="#email">Email</a></li>
<li><a class="reference internal" href="#error-reporting">Error Reporting</a></li>
<li><a class="reference internal" href="#file-storage">File Storage</a></li>
<li><a class="reference internal" href="#forms">Forms</a></li>
<li><a class="reference internal" href="#internationalization">Internationalization</a></li>
<li><a class="reference internal" href="#management-commands">Management Commands</a></li>
<li><a class="reference internal" href="#models">Models</a></li>
<li><a class="reference internal" href="#pagination">Pagination</a></li>
<li><a class="reference internal" href="#requests-and-responses">Requests and Responses</a></li>
<li><a class="reference internal" href="#security">Security</a></li>
<li><a class="reference internal" href="#templates">Templates</a></li>
<li><a class="reference internal" href="#tests">Tests</a></li>
<li><a class="reference internal" href="#urls">URLs</a></li>
<li><a class="reference internal" href="#utilities">Utilities</a></li>
<li><a class="reference internal" href="#miscellaneous">Miscellaneous</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#backwards-incompatible-changes-in-3-1">Backwards incompatible changes in 3.1</a><ul>
<li><a class="reference internal" href="#database-backend-api">Database backend API</a></li>
<li><a class="reference internal" href="#dropped-support-for-mariadb-10-1">Dropped support for MariaDB 10.1</a></li>
<li><a class="reference internal" href="#contrib-admin-browser-support"><code class="docutils literal notranslate"><span class="pre">contrib.admin</span></code> browser support</a></li>
<li><a class="reference internal" href="#abstractuser-first-name-max-length-increased-to-150"><code class="docutils literal notranslate"><span class="pre">AbstractUser.first_name</span></code> <code class="docutils literal notranslate"><span class="pre">max_length</span></code> increased to 150</a></li>
<li><a class="reference internal" href="#id1">Miscellaneous</a></li>
</ul>
</li>
<li><a class="reference internal" href="#features-deprecated-in-3-1">Features deprecated in 3.1</a><ul>
<li><a class="reference internal" href="#postgresql-jsonfield">PostgreSQL <code class="docutils literal notranslate"><span class="pre">JSONField</span></code></a></li>
<li><a class="reference internal" href="#id2">Miscellaneous</a></li>
</ul>
</li>
<li><a class="reference internal" href="#features-removed-in-3-1">Features removed in 3.1</a></li>
</ul>
</li>
</ul>

  <h4>上一个主题</h4>
  <p class="topless"><a href="3.1.1.html"
                        title="上一章">Django 3.1.1 release notes</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="3.0.14.html"
                        title="下一章">Django 3.0.14 release notes</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/releases/3.1.txt"
            rel="nofollow">显示源代码</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>快速搜索</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="转向" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">7月 23, 2021</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="3.1.1.html" title="Django 3.1.1 release notes">previous</a>
     |
    <a href="index.html" title="Release notes" accesskey="U">up</a>
   |
    <a href="3.0.14.html" title="Django 3.0.14 release notes">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>